<template>
  <view class="page">
    <view class="items">
      <view class="item tcard" v-for="item in list" :key="item.id">
        <!-- <view class="title">
          {{ item.companyName }}
        </view> -->
        
        <view class="tform no-border">
          <view class="tform-item">
            <view class="label">
              订单类型
            </view>
            <view class="value">
              团检
            </view>
          </view>
          <view class="tform-item">
            <view class="label">
              体检人
            </view>
            <view class="value">
              {{userInfo.name}}
            </view>
          </view>
          <view class="tform-item">
            <view class="label">
              体检套餐
            </view>
            <view class="value">
              {{item.codename}}
            </view>
          </view>
          <view class="tform-item">
            <view class="label">
              有效时间
            </view>
            <view class="value">
              {{item.bespeak_time}}
              <!-- {{item.reserveTime.substr(0, 4) + '-' + item.reserveTime.substr(4, 2) + '-' + item.reserveTime.substr(6, 2)}} -->
            </view>
          </view>
        </view>
        <view style="padding: 0 12upx;">
          <view class="bottom">
            <view class="status" :style="{color: item.is_delete == 2 ? 'rgba(0,0,0,0.24)' : '#5DD2B1'}">
              {{ item.is_delete == 2 ? '已取消' : ''}}
              <!-- {{ status[item.status] }} -->
            </view>
            <view v-if="item.is_delete != 2" class="btn light" @click="cancalGroup(item)">
              取消订单
            </view>
          </view>
        </view>
        
      </view>
    </view>
  </view>
</template>

<script>
  import { mapGetters, mapActions } from 'vuex'
  import {getOrderList, cancalGroup} from '@/api/physical.js'
  // const status = {
  //   0: '待提交',
  //   1: '待支付',
  //   2: '支付取消',
  //   3: '成功',
  //   5: '已取消',
  // }
  export default {
    data() {
      return {
        // status,
        list:[]
      }
    },
    computed:{
      ...mapGetters(['userInfo', 'userList']),
    },
    onLoad() {
      this.getOrderList()
    },
    methods: {
      getOrderList() {
        const data = {
          identityCard: this.userInfo.idCard
        }
        getOrderList(data).then(res => {
          this.list = res
        })
      },
      cancalGroup(item) {
        uni.showLoading()
        const data = {
          dealCode: item.deal_code,
          serviceNumber: item.serviceNumber
        }
        cancalGroup(data).then(res => {
          uni.hideLoading()
          this.$u.toast('取消成功')
          this.list = []
          this.getOrderList()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  
.items {
  flex: 1;
  overflow: auto;
  .item {
    // padding: 32upx;
    .tform-item {
      padding: 12upx;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid rgba(0,0,0,0.12);
      padding-top: 20upx;
      .btn {
        width: 122upx;
        height: 42upx;
        background: $theme-color;
        border-radius: 42upx;
        text-align: center;
        line-height: 42upx;
        color: #FFF;
        font-size: 24upx;
      }
      .light {
        background: transparent;
        border: 1px solid $theme-color;
        color: $theme-color;
      }
    }
  }
}
</style>
